package CapaDeDatos;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Serializador<D> {

        public void serializar(D redSocial, String url) {
                try {
                        FileOutputStream fos = new FileOutputStream(url);
                        ObjectOutputStream out = new ObjectOutputStream(fos);
                        out.writeObject(redSocial);
                        out.close();
                } catch (Exception ex) {
                        ex.getStackTrace();
                }
        }

        @SuppressWarnings("unchecked")
        public D deserializar(String url) {
                D ret = null;
                try {
                        FileInputStream fis = new FileInputStream(url);
                        ObjectInputStream in = new ObjectInputStream(fis);
                        ret = (D) in.readObject();
                        in.close();
                } catch (Exception ex) {
                        ex.getStackTrace();
                }
                return ret;
        }
}

